{% extends "base_content_type.html" %}

{% block fields %}
<li><label for="url">url</label>
<input id="url" name="url" size="100" value="{{ content.url }}"/>
</li>

<li><div id="searchcontrol"><a id="searchaction" class="action">Search?</a></div>
</li>
{% endblock %}

{% block editor_script_extra %}
  var attachHandler = function() {
    $('#searchaction').one('click', function() {
      if (!minerva.vidSearchControl) {
        minerva.vidSearchControl = new google.search.SearchControl();
        var vidSearch = new google.search.VideoSearch();
        minerva.vidSearchControl.addSearcher(vidSearch);
        }

      var elq = $('#searchcontrol');
      minerva.vidSearchControl.draw(elq.get(0));
      // Intercept click events to anchors
      elq.intercept('click', 'img', function(e) {
        e.preventDefault();
        var img = e.target;
        var anchor = img.parentNode;
        $('input#url').val(anchor.href);
        });
      });
    }

  if (!google.search) {
    var gopts = {
      'nooldnames': true,
      'language': 'en',
      'callback': attachHandler,
      };
    google.load('search', '1', gopts);
    }
  else {
    attachHandler()
    }
{% endblock %}

{% block attributes %}
{% ifequal subtype "video" %}
<embed id="VideoPlayback" type="application/x-shockwave-flash"
       src="http://video.google.com/googleplayer.swf?docId={{ vid }}&hl=en"
       flashvars="" wmode="transparent" width="425" height="355">
</embed>
{% endifequal %}
{% ifequal subtype "youtube" %}
<object width="425" height="355">
<param name="movie" value="{{ content.url }}"></param>
<param name="wmode" value="transparent"></param>
<embed src=" http://www.youtube.com/v/{{ vid }}&hl=en" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed>
</object>
{% endifequal %}

{% ifequal subtype "vimeo" %}
<object width="600" height="400">
<param name="allowfullscreen" value="true" />
<param name="allowscriptaccess" value="always" />
<param name="movie" value="{{ content.url }}" />
<embed src="http://vimeo.com/moogaloop.swf?clip_id={{ vid }}&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="425" height="355"></embed>
</object>
{% endifequal %}

{% endblock %}
